<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Prime - prime: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-Prime-label-Example">Example</a>
    <li><a href="#class-Prime-label-Retrieving+the+instance">Retrieving the instance</a>
    <li><a href="#class-Prime-label-Generators">Generators</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><span class="include">Enumerable</span>
    <li><span class="include">Singleton</span>
  </ul>
</div>

        
<div id="extends-section" class="nav-section">
  <h3>Extended With Modules</h3>

  <ul class="link-list">
    <li><span class="extend">Forwardable</span>
  </ul>
</div>

        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-include-3F">#include?</a>
    <li ><a href="#method-i-int_from_prime_division">#int_from_prime_division</a>
    <li ><a href="#method-i-prime-3F">#prime?</a>
    <li ><a href="#method-i-prime_division">#prime_division</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Prime">
    <h1 id="class-Prime" class="class">
      class Prime
    </h1>

    <section class="description">
    
<p>The set of all prime numbers.</p>

<h2 id="class-Prime-label-Example">Example<span><a href="#class-Prime-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-constant">Prime</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value">100</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">prime</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">prime</span>  <span class="ruby-comment">#=&gt; 2, 3, 5, 7, 11, ...., 97</span>
<span class="ruby-keyword">end</span>
</pre>

<p><a href="Prime.html"><code>Prime</code></a> is Enumerable:</p>

<pre class="ruby"><span class="ruby-constant">Prime</span>.<span class="ruby-identifier">first</span> <span class="ruby-value">5</span> <span class="ruby-comment"># =&gt; [2, 3, 5, 7, 11]</span>
</pre>

<h2 id="class-Prime-label-Retrieving+the+instance">Retrieving the instance<span><a href="#class-Prime-label-Retrieving+the+instance">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>For convenience, each instance method of <code>Prime</code>.instance can be accessed as a class method of <code>Prime</code>.</p>

<p>e.g.</p>

<pre class="ruby"><span class="ruby-constant">Prime</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">prime?</span>(<span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">Prime</span>.<span class="ruby-identifier">prime?</span>(<span class="ruby-value">2</span>)           <span class="ruby-comment">#=&gt; true</span>
</pre>

<h2 id="class-Prime-label-Generators">Generators<span><a href="#class-Prime-label-Generators">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>A “generator” provides an implementation of enumerating pseudo-prime numbers and it remembers the position of enumeration and upper bound. Furthermore, it is an external iterator of prime enumeration which is compatible with an Enumerator.</p>

<p><code>Prime</code>::<code>PseudoPrimeGenerator</code> is the base class for generators. There are few implementations of generator.</p>
<dl class="rdoc-list label-list"><dt><code>Prime</code>::<code>EratosthenesGenerator</code>
<dd>
<p>Uses Eratosthenes’ sieve.</p>
</dd><dt><code>Prime</code>::<code>TrialDivisionGenerator</code>
<dd>
<p>Uses the trial division method.</p>
</dd><dt><code>Prime</code>::<code>Generator23</code>
<dd>
<p>Generates all positive integers which are not divisible by either 2 or 3. This sequence is very bad as a pseudo-prime sequence. But this is faster and uses much less memory than the other generators. So, it is suitable for factorizing an integer which is not large but has many prime factors. e.g. for <a href="Prime.html#method-i-prime-3F"><code>Prime#prime?</code></a> .</p>
</dd></dl>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="VERSION">VERSION
          <dd>
        </dl>
        </section>



                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-each" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each</span><span
                                class="method-args">(ubound = nil, generator = EratosthenesGenerator.new, &amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Iterates the given block over all prime numbers.</p>

<h2 id="method-i-each-label-Parameters">Parameters<span><a href="#method-i-each-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h2>
<dl class="rdoc-list note-list"><dt><code>ubound</code>
<dd>
<p>Optional. An arbitrary positive number. The upper bound of enumeration. The method enumerates prime numbers infinitely if <code>ubound</code> is nil.</p>
</dd><dt><code>generator</code>
<dd>
<p>Optional. An implementation of pseudo-prime generator.</p>
</dd></dl>

<h2 id="method-i-each-label-Return+value">Return value<span><a href="#method-i-each-label-Return+value">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>An evaluated value of the given block at the last time. Or an enumerator which is compatible to an <code>Enumerator</code> if no block given.</p>

<h2 id="method-i-each-label-Description">Description<span><a href="#method-i-each-label-Description">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Calls <code>block</code> once for each prime number, passing the prime as a parameter.</p>
<dl class="rdoc-list note-list"><dt><code>ubound</code>
<dd>
<p>Upper bound of prime numbers. The iterator stops after it yields all prime numbers p &lt;= <code>ubound</code>.</p>
</dd></dl>

                              <div class="method-source-code" id="each-source">
            <pre><span class="ruby-comment"># File prime-0.1.2/lib/prime.rb, line 212</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each</span>(<span class="ruby-identifier">ubound</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">generator</span> = <span class="ruby-constant">EratosthenesGenerator</span>.<span class="ruby-identifier">new</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">generator</span>.<span class="ruby-identifier">upper_bound</span> = <span class="ruby-identifier">ubound</span>
  <span class="ruby-identifier">generator</span>.<span class="ruby-identifier">each</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-include-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">include?</span><span
                                class="method-args">(obj)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if <code>obj</code> is an <a href="Integer.html"><code>Integer</code></a> and is prime.  Also returns true if <code>obj</code> is a Module that is an ancestor of <code>Prime</code>. Otherwise returns false.</p>

                              <div class="method-source-code" id="include-3F-source">
            <pre><span class="ruby-comment"># File prime-0.1.2/lib/prime.rb, line 220</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">include?</span>(<span class="ruby-identifier">obj</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">obj</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Integer</span>
    <span class="ruby-identifier">prime?</span>(<span class="ruby-identifier">obj</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Module</span>
    <span class="ruby-constant">Module</span>.<span class="ruby-identifier">instance_method</span>(<span class="ruby-value">:include?</span>).<span class="ruby-identifier">bind</span>(<span class="ruby-constant">Prime</span>).<span class="ruby-identifier">call</span>(<span class="ruby-identifier">obj</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-int_from_prime_division" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">int_from_prime_division</span><span
                                class="method-args">(pd)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Re-composes a prime factorization and returns the product.</p>

<p>For the decomposition:</p>

<pre>[[p_1, e_1], [p_2, e_2], ..., [p_n, e_n]],</pre>

<p>it returns:</p>

<pre>p_1**e_1 * p_2**e_2 * ... * p_n**e_n.</pre>

<h2 id="method-i-int_from_prime_division-label-Parameters">Parameters<span><a href="#method-i-int_from_prime_division-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h2>
<dl class="rdoc-list note-list"><dt><code>pd</code>
<dd>
<p>Array of pairs of integers. Each pair consists of a prime number – a prime factor – and a natural number – its exponent (multiplicity).</p>
</dd></dl>

<h2 id="method-i-int_from_prime_division-label-Example">Example<span><a href="#method-i-int_from_prime_division-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-constant">Prime</span>.<span class="ruby-identifier">int_from_prime_division</span>([[<span class="ruby-value">3</span>, <span class="ruby-value">2</span>], [<span class="ruby-value">5</span>, <span class="ruby-value">1</span>]])  <span class="ruby-comment">#=&gt; 45</span>
<span class="ruby-value">3</span><span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">*</span> <span class="ruby-value">5</span>                                         <span class="ruby-comment">#=&gt; 45</span>
</pre>

                              <div class="method-source-code" id="int_from_prime_division-source">
            <pre><span class="ruby-comment"># File prime-0.1.2/lib/prime.rb, line 268</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">int_from_prime_division</span>(<span class="ruby-identifier">pd</span>)
  <span class="ruby-identifier">pd</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">1</span>){<span class="ruby-operator">|</span><span class="ruby-identifier">value</span>, (<span class="ruby-identifier">prime</span>, <span class="ruby-identifier">index</span>)<span class="ruby-operator">|</span>
    <span class="ruby-identifier">value</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">prime</span><span class="ruby-operator">**</span><span class="ruby-identifier">index</span>
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-prime-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">prime?</span><span
                                class="method-args">(value, generator = Prime::Generator23.new)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if <code>value</code> is a prime number, else returns false. <a href="Integer.html#method-i-prime-3F"><code>Integer#prime?</code></a> is much more performant.</p>

<h2 id="method-i-prime-3F-label-Parameters">Parameters<span><a href="#method-i-prime-3F-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h2>
<dl class="rdoc-list note-list"><dt><code>value</code>
<dd>
<p>an arbitrary integer to be checked.</p>
</dd><dt><code>generator</code>
<dd>
<p>optional. A pseudo-prime generator.</p>
</dd></dl>

                              <div class="method-source-code" id="prime-3F-source">
            <pre><span class="ruby-comment"># File prime-0.1.2/lib/prime.rb, line 238</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">prime?</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">generator</span> = <span class="ruby-constant">Prime</span><span class="ruby-operator">::</span><span class="ruby-constant">Generator23</span>.<span class="ruby-identifier">new</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Expected a prime generator, got #{generator}&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">generator</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value">:each</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Expected an integer, got #{value}&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:integer?</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">integer?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">2</span>
  <span class="ruby-identifier">generator</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">num</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">q</span>,<span class="ruby-identifier">r</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">divmod</span> <span class="ruby-identifier">num</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">q</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">num</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-prime_division" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">prime_division</span><span
                                class="method-args">(value, generator = Prime::Generator23.new)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the factorization of <code>value</code>.</p>

<p>For an arbitrary integer:</p>

<pre>p_1**e_1 * p_2**e_2 * ... * p_n**e_n,</pre>

<p><a href="Prime.html#method-i-prime_division"><code>prime_division</code></a> returns an array of pairs of integers:</p>

<pre>[[p_1, e_1], [p_2, e_2], ..., [p_n, e_n]].</pre>

<p>Each pair consists of a prime number – a prime factor – and a natural number – its exponent (multiplicity).</p>

<h2 id="method-i-prime_division-label-Parameters">Parameters<span><a href="#method-i-prime_division-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h2>
<dl class="rdoc-list note-list"><dt><code>value</code>
<dd>
<p>An arbitrary integer.</p>
</dd><dt><code>generator</code>
<dd>
<p>Optional. A pseudo-prime generator. <code>generator</code>.succ must return the next pseudo-prime number in ascending order. It must generate all prime numbers, but may also generate non-prime numbers, too.</p>
</dd></dl>

<h3 id="method-i-prime_division-label-Exceptions">Exceptions<span><a href="#method-i-prime_division-label-Exceptions">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><code>ZeroDivisionError</code>
<dd>
<p>when <code>value</code> is zero.</p>
</dd></dl>

<h2 id="method-i-prime_division-label-Example">Example<span><a href="#method-i-prime_division-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-constant">Prime</span>.<span class="ruby-identifier">prime_division</span>(<span class="ruby-value">45</span>)  <span class="ruby-comment">#=&gt; [[3, 2], [5, 1]]</span>
<span class="ruby-value">3</span><span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">*</span> <span class="ruby-value">5</span>                  <span class="ruby-comment">#=&gt; 45</span>
</pre>

                              <div class="method-source-code" id="prime_division-source">
            <pre><span class="ruby-comment"># File prime-0.1.2/lib/prime.rb, line 303</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">prime_division</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">generator</span> = <span class="ruby-constant">Prime</span><span class="ruby-operator">::</span><span class="ruby-constant">Generator23</span>.<span class="ruby-identifier">new</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ZeroDivisionError</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">value</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">value</span>
    <span class="ruby-identifier">pv</span> = [[<span class="ruby-value">-1</span>, <span class="ruby-value">1</span>]]
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">pv</span> = []
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">generator</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">prime</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">count</span> = <span class="ruby-value">0</span>
    <span class="ruby-keyword">while</span> (<span class="ruby-identifier">value1</span>, <span class="ruby-identifier">mod</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">divmod</span>(<span class="ruby-identifier">prime</span>)
           <span class="ruby-identifier">mod</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">value</span> = <span class="ruby-identifier">value1</span>
      <span class="ruby-identifier">count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">pv</span>.<span class="ruby-identifier">push</span> [<span class="ruby-identifier">prime</span>, <span class="ruby-identifier">count</span>]
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value1</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">prime</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
    <span class="ruby-identifier">pv</span>.<span class="ruby-identifier">push</span> [<span class="ruby-identifier">value</span>, <span class="ruby-value">1</span>]
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">pv</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

